const cmd = require('node-cmd');
const treeKill = require('tree-kill');

// 获取所有node进程PID并终止
cmd.get('tasklist /FI "IMAGENAME eq node.exe"', (err, data) => {
  if (err) {
    console.error('Error getting process list:', err);
    return;
  }
  
  const lines = data.split('\n');
  lines.slice(1).forEach(line => {
    const pid = line.trim().split(/\s+/)[1];
    if (pid) {
      treeKill(parseInt(pid), 'SIGTERM', (err) => {
        if (err) console.error(`Error killing process ${pid}:`, err);
        else console.log(`Terminated process ${pid}`);
      });
    }
  });
});